package service

import (
	"context"
	"video-srv/basic/config"
	__ "video-srv/basic/proto/rpc"
	"video-srv/handler/model"
)

func (s *VideoServer) AddDanMu(_ context.Context, in *__.AddDanMuReq) (*__.AddDanMuResp, error) {
	danMu := model.DanMu{
		UserId:    int(in.UserId),
		VideoId:   int(in.VideoId),
		EpisodeId: int(in.EpisodeId),
		Duration:  int(in.Duration),
		Content:   in.Content,
		Color:     in.Color,
	}
	err := danMu.AddDanMu(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.AddDanMuResp{
		DanMuId: int64(danMu.ID),
	}, nil
}
func (s *VideoServer) GetDanMu(_ context.Context, in *__.GetDanMuReq) (*__.GetDanMuResp, error) {
	danMu := model.DanMu{}
	list, err := danMu.GetDanMu(config.DB, int(in.UserId), int(in.VideoId), int(in.EpisodeId), int(in.Duration))
	if err != nil {
		return nil, err
	}
	return &__.GetDanMuResp{
		List: list,
	}, nil
}
